package event;

import protocol.Node;


/*
 * Created on 2005-4-4
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */

/**
 * @author Lizzy
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Event implements Comparable{
	
	static int uniqueID=0;
	int time;
	char type;
	int id;
	Node source;
	Node des;
	Object args;
	
	//define the value of type
	public static final char JOIN=1;
	public static final char JOINED = 2;
	public static final char LOOKUP = 3;
	public static final char LEAVE = 4;
	
	/**---event-----args-----explaination
	 *  	join    Node     well known nodes
	 *  	send	Message	 message to be sent
	 *  	lookup
	 *  	leave	null	 
	 * 
	 */

	
	public Event(char type,int time,Node source,Node des,Object args){
		id=uniqueID++%Integer.MAX_VALUE;
		this.time=time;
		this.type=type;
		this.source=source;
		this.des=des;
		this.args=args;
	}
	public int compareTo(Object arg0) {
		// TODO Auto-generated method stub
		if (time<((Event) arg0).time){
			return -1;
		}else if(time>((Event) arg0).time){
			return 1;
		}else return 0;
	}
	
	public Object getArgs() {
		return args;
	}
	public char getType() {
		return type;
	}
	public int getTime(){
		return time;
	}
	public static String printType(char type){
		switch(type){
		case JOIN:	return "join";
		case LEAVE:	return "leave";
		case LOOKUP:return "lookup";
		default:return "unknown";
		}
	}
}

